package com.cloudptt.api.product.func.call.group.fsm.call;

import com.cloudptt.api.comm.CauseCont;
import com.cloudptt.api.comm.CommDlg;
import com.cloudptt.api.comm.Common;
import com.cloudptt.api.models.call.RtcpMsg;
import com.cloudptt.api.pjsua2.MyCall;
import com.cloudptt.api.product.func.addr.IAddrOp;
import com.cloudptt.api.product.func.call.CallAttr;
import com.cloudptt.api.product.func.call.CallConst;
import com.cloudptt.api.product.func.call.CallListener;
import com.cloudptt.api.product.func.call.CallTimer;
import com.cloudptt.api.product.func.call.ICallMute;
import com.cloudptt.api.product.func.call.group.HalfCallInfo;
import com.cloudptt.api.product.func.call.group.GroupCallSpeakListener;
import com.cloudptt.api.product.func.call.group.fsm.IRollback;
import com.cloudptt.api.product.func.call.group.fsm.floor.FloorAgent;
import com.cloudptt.api.product.func.call.group.fsm.floor.ISubState;
import com.cloudptt.api.product.func.call.group.fsm.video.VideoAgent;
import com.cloudptt.api.product.func.call.single.SingleCallAgent;
import com.cloudptt.api.product.func.lbs.AlarmTimer;
import com.cloudptt.api.product.func.lbs.IAlarmTimeout;
import com.cloudptt.api.product.log.Log;
import com.cloudptt.api.product.operator.CallOperator;
import com.cloudptt.api.product.res.Resource;
import com.mcptt.config.model.McIdInfo;
import com.mcptt.db.model.AddrInfo;
import com.mcptt.db.model.UserInfo;

import android.content.Context;
import android.os.Handler;
import android.os.Message;


public class GroupCallAgent implements ICallState,ISubState,IRollback,IAlarmTimeout,ICallMute
{
	public final static String Log_Key = "GroupCallAgent";
	private ICallState currentState = null;
	
	private Class<?> cls = null;
	private CallListener listener = null;
	private GroupCallSpeakListener floorListener = null;
//	private GroupCallVideoListener videoListener = null;
	
	private Context ctx = null;
	private CallAttr callAttr = null;
	private McIdInfo mcIdInfo = null;

	private CallOperator operator = null;
	private IAddrOp addOp = null;
	private CallTimer callTime = null;

	private FloorAgent floorAgent = null;
	private VideoAgent videoAgent = null;
	
	private RtcpMsg lastRtcpMsg = null;
	
	private String curCallIdStr = MyCall.DEF_CALL_ID_STR;
	private String callkey = null;
	private String timeDesc = null;
	
	private AlarmTimer keepLiveTimer = null;
	private volatile boolean isStartTimer = false;
	public final static String TimerOutKey_Negotiate= "gcall_negotiate";

	private boolean isRecvRelease = false;
	
	public GroupCallAgent(Context ctx,CallAttr callAttr,McIdInfo mcIdInfo,CallOperator operator,IAddrOp addOp)
	{
		Log.d(GroupCallAgent.Log_Key, "CallAgent callAttr = " + callAttr);
		this.ctx = ctx;
		this.callAttr = callAttr;
		this.callkey = callAttr.getCallKey();
		this.mcIdInfo = mcIdInfo;
//		this.setCur = setCur;
		this.currentState = new InitialState(this);
		this.operator = operator;
		this.addOp = addOp;
		this.callTime = CallTimer.getInstance();
	}
	
	public void updateCallIdStr(String callIdStr)
	{
		Log.d(GroupCallAgent.Log_Key, "updateCallId callIdStr = " + callIdStr);
		this.curCallIdStr = callIdStr;
		if(floorAgent != null)
		{
			floorAgent.updateCallIdStr(callIdStr);
		}
	}
	public void setPrivacyClass(Class cls)
	{
		this.cls = cls;
	}
	public void setListener(CallListener listener,GroupCallSpeakListener floorListener)
	{
		Log.d(GroupCallAgent.Log_Key, "setListener ");
		this.listener = listener;
		this.floorListener = floorListener;
		if(floorAgent != null)
		{
			floorAgent.setListener(floorListener);
		}
//		this.videoListener = videoListener;
		if(videoAgent != null)
		{
			videoAgent.setListener(null);
		}
	}

//	public void setCurGroupInfo(UserInfo curGroupInfo) {
//		this.curGroupInfo = curGroupInfo;
//	}

	public void goToState(int nextState){
		ICallState callState = null;
		Log.d(GroupCallAgent.Log_Key, "goToState:["+ CallConst.stateTag(this.currentState.getState()) +
				" to "+ CallConst.stateTag(nextState) + "]");

			switch (nextState) {
			case CallConst.CallState_InitState:
				callState = new InitialState(this);
				break;
			case CallConst.CallState_ConnectingState:
				callState = new ConnectingState(ctx,this);
				break;
			case CallConst.CallState_Activite:
				callState = new ActiviteState(this);
				break;
			case CallConst.CallState_DisconnectingState:
				callState = new DisconnectingState(ctx,this);
				break;
			default:
				Log.d(GroupCallAgent.Log_Key, "Illegal state="+ nextState);
				return;//!!!
			}
			this.setCurrentState(callState);
	}
	public void setDefaultGroupInfo(AddrInfo info)
	{
		if(floorAgent != null)
		{
			this.floorAgent.setDefaultGroupInfo(info);
		}
	}

	
	public void setCurrentState(ICallState currentState) 
	{
		this.currentState.destory();
		this.currentState = currentState;
		int talkState = currentState.getState();
		
		if(listener != null)
		{
			listener.updateCallState(callkey,talkState,false);
		}
		
		if(CallConst.CallState_InitState == talkState)
		{
			if(floorAgent != null)
			{
				this.floorAgent.clearResource();
				this.floorAgent = null;
			}

			if(videoAgent != null)
			{
				this.videoAgent.clearResource();
				this.videoAgent = null;
			}

			this.operator.clearResourceForCallEnd(curCallIdStr);
			this.addOp.setCurGroupInfo(null);
			this.stopTimer();
		}
		else if(CallConst.CallState_Activite == talkState)
		{
			startTimer();
		}
	}
	
	public void initServiveAgentByMcType(boolean isGranted)
	{
		Log.d( Log_Key, "initServiveAgentByMcType isGranted = " + isGranted);
		if(floorAgent == null)
		{
			initFloorAgent(isGranted,lastRtcpMsg);
		}
//		else if(CallAttr.McType_VIDEO == mcType
//				&& videoAgent == null)
//		{
//			initVideoAgent(isGranted,lastRtcpMsg);
//		}
		
		lastRtcpMsg = null;
	}

	protected void initFloorAgent(boolean isGranted,RtcpMsg lastRtcpMsg)
	{
		Log.d( Log_Key, "initFloorAgent isGranted = " + isGranted + " lastRtcpMsg = " + lastRtcpMsg);
//		if(floorAgent != null)
//		{
//			floorAgent.clearResource();
//			floorAgent = null;
//		}
		String callKey = this.callAttr.getCallKey();
		floorAgent = new FloorAgent(this.ctx,curCallIdStr,callKey,operator,addOp,callTime,this);
		floorAgent.setFloorInfo(callAttr,mcIdInfo);
		floorAgent.setListener(floorListener);
		if(isGranted)
		{
			floorAgent.goToState(CallConst.FloorState_Permission,null);
		}
		if(lastRtcpMsg != null)
		{
			floorAgent.receiveRtcpMsg(lastRtcpMsg);
		}
		Log.d( Log_Key, "initFloorAgent end");
	}
	
	protected void initVideoAgent(boolean isGranted,RtcpMsg lastRtcpMsg)
	{
		Log.d( Log_Key, "initVideoAgent isGranted = " + isGranted + "lastRtcpMsg = " + lastRtcpMsg);
//		if (videoAgent != null) {
//			videoAgent.clearResource();
//			videoAgent = null;
//		}

		videoAgent = new VideoAgent(this.ctx, curCallIdStr,operator,addOp,callTime, this);
		videoAgent.setListener(null);
		if(isGranted)
		{
			videoAgent.goToState(CallConst.VideoState_Permission);
		}
		if(lastRtcpMsg != null)
		{
			videoAgent.receiveRtcpMsg(lastRtcpMsg);
		}
	}

//	private boolean cachedVideo = false;
//	public void onDisplayVideo(int callId, boolean show)
//	{
//		Log.d( Log_Key, GroupCallConst.stateTag(this.currentState.getState()) +" cachedVideo=" + cachedVideo + ",show=" + show );
//		cachedVideo = show ;
//		if( listener != null ) 
//		{
//			
//			listener.onDisplayVideo( callId, show );
//		}
////		if( !cachedVideo ) {
////			if( speakAgent != null
////					&& GroupCallConst.FloorState_NoPermission == speakAgent
////					.getCurrentState( ) ) {
//////				initServiceAgent( );
////			}
////		}
//	}

	public int doUserAction(int btnAction)
	{
		Log.d( GroupCallAgent.Log_Key,
				"callkey = " + callkey + " " + CallConst.stateTag(this.currentState.getState()) + " doUserAction = " + CallConst.userActionTag( btnAction )
				+ ",speakAgent=" + ( floorAgent != null )
				+ ",videoAgent=" + ( videoAgent != null ) );
		if(isRecvRelease)
		{
			int result = CauseCont.OperateErr_OpQuick;//floorAgent.do UserAction( btnAction );
			Log.d(GroupCallAgent.Log_Key, "doBtnAction btnAction = " + btnAction +  " result = " + result + " isRecvRelease = " + isRecvRelease);
		}
		if(CallConst.BtnAction_Request == btnAction
				|| btnAction == CallConst.BtnAction_Hangup)
		{
			mHandler.removeMessages(MsgId_Release);
		}
		int result = CauseCont.OperateErr_NoAgent;
		if(videoAgent != null
				&& btnAction != CallConst.BtnAction_Make
				&& btnAction != CallConst.BtnAction_Accept
				&& btnAction != CallConst.BtnAction_Hangup) 
		{
			result = videoAgent.doUserAction( btnAction );
			Log.d(GroupCallAgent.Log_Key, "videoAgent.doBtnAction btnAction = " + btnAction +  " result = " + result);
		} 
		else if( floorAgent != null
				&& btnAction != CallConst.BtnAction_Make
				&& btnAction != CallConst.BtnAction_Accept
				&& btnAction != CallConst.BtnAction_Hangup ) 
		{
			result = floorAgent.doUserAction( btnAction );
			Log.d(GroupCallAgent.Log_Key, "speakAgent.doBtnAction btnAction = " + btnAction +  " result = " + result);
		} 
		else if( floorAgent == null
				&& btnAction == CallConst.BtnAction_Release) 
		{
			isRecvRelease = true;
			result = CauseCont.OperateCheck_Suc;//floorAgent.do UserAction( btnAction );
			Log.d(GroupCallAgent.Log_Key, "floorAgent == null speakAgent.doBtnAction btnAction = " + btnAction +  " result = " + result);
			Message msg = mHandler.obtainMessage(MsgId_Release);
			mHandler.sendMessageDelayed(msg, 1000);
		}
		else 
		{
			result =  currentState.doUserAction( btnAction );
			Log.d(GroupCallAgent.Log_Key, "callAgent.doBtnAction btnAction is " + btnAction +  " result is " + result);
		}
		return result;
	}
	public boolean isActiveCall()
	{
		//		if( operator!=null)
		//		{
		//			return operator.isActiveCall();
		//		}
		int talkState = currentState.getState();
		if(CallConst.CallState_InitState != talkState)
		{
			return true;
		}
		return false;
	}

	public void receiveCallAction(int callAction)
	{
		Log.d( GroupCallAgent.Log_Key,
				CallConst.stateTag(this.currentState.getState()) + " receiveCallAction callAction = "
						+ CallConst.sessionTag( callAction ) );

		currentState.receiveCallAction( callAction );
	}
	public void receiveRtcpMsg(RtcpMsg msg)
	{
		Log.d(GroupCallAgent.Log_Key, CallConst.stateTag(this.currentState.getState()) + " receiveSpeakInfo RtcpMsg = " + msg);
		if(msg == null)
		{
			return;
		}
		if(!msg.isVideoRtcpMsg())
		{
			if(floorAgent != null)
			{
				this.floorAgent.receiveRtcpMsg(msg);
			}
			else
			{
				lastRtcpMsg = msg;
				Log.d(GroupCallAgent.Log_Key, "receiveSpeakInfo speakAgent = null");
			}
		}
		else
		{
			if(videoAgent != null)
			{
				this.videoAgent.receiveRtcpMsg(msg);
			}
			else
			{
				lastRtcpMsg = msg;
				Log.d(GroupCallAgent.Log_Key, "receiveSpeakInfo videoAgent = null");
			}
		}
	}
	public void updateTakenUser(String callType,AddrInfo gInfo,AddrInfo user)
	{}

	public int getState()
	{
		return this.currentState.getState();
	}

	public HalfCallInfo getCallInfo()
	{
		Log.d(GroupCallAgent.Log_Key, "getCallInfo");
		int callState = currentState.getState();
		int speakState = CallConst.FloorState_Null;
		AddrInfo floorUserInfo = null;
		if(floorAgent != null)
		{
			speakState = floorAgent.getState();
			floorUserInfo = floorAgent.getFloorUserInfo();
		}
		int videoState = CallConst.VideoState_Begin;
		AddrInfo videoUserInfo = null;
		if( videoAgent != null){
			videoState = videoAgent.getState();
			videoUserInfo = videoAgent.getVideoUserInfo();
		}
		return new HalfCallInfo(callAttr,callState,speakState,floorUserInfo, videoState, videoUserInfo);
	}

	public void rollback()
	{
		Log.d(GroupCallAgent.Log_Key, "IdleState rollbackState");
//		if( !cachedVideo ) 
		{
			this.currentState.doUserAction(CallConst.BtnAction_Hangup);
		}
	}

	public void updateTimer(CallTimer time) {
		this.callTime.updateTime(time);
		if(floorAgent != null)
		{
			this.floorAgent.updateTime(time);
		}
		if(videoAgent != null)
		{
			this.videoAgent.updateTime(time);
		}
	}


	@Override
	public void destory() {
		// TODO Auto-generated method stub
		if(this.operator != null)
		{
			//this.operator.hangupCall(curCallIdStr, 486);
			this.operator.clearResourceForCallEnd(curCallIdStr);
		}
		if(mHandler != null)
		{
			mHandler.removeMessages(MsgId_Release);
		}
		mHandler = null;
		timeDesc = null;
		if(currentState != null)
		{
			this.currentState.destory();
		}
		this.stopTimer();
	}

	public void incomingCall(UserInfo incomingInfo)
	{
		Log.d(GroupCallAgent.Log_Key, "incomingCall incomingInfo = " + incomingInfo);
		
//		if(this.listener != null)
//		{
//			this.listener.incomingCall(incomingInfo);
//		}
	}

	protected int doMakeCallAction()
	{
		Context ctx = this.getCtx();
//		boolean isVideo = false;
//		int callType = CallAttr.CallType_Group;
		Log.d(GroupCallAgent.Log_Key, "doMakeCallAction callAttr = " + callAttr);
		if(callAttr == null)
		{
			return CauseCont.OperateErr_Exception;
		}
		CallOperator operator = this.getOperator();
		if(null == operator
				|| null == ctx)
		{
			Log.d(GroupCallAgent.Log_Key, "doMakeCallAction operator_null");
			String errStr =  Resource.getString("operator_null");//ctx.getString(R.string.operator_null);
			CommDlg.showToast(ctx,errStr);
			return CauseCont.OperateCheck_Sys_UserKeyNull;
		}
//		if(curGroupInfo == null)
//		{
//			String errStr =  Resource.getString("group_null");//this.agent.getCtx().getString(R.string.group_null);
//			CommDlg.showToast(ctx,errStr);
//			return CauseCont.OperateErr_GroupNull;
//		}
//		Log.d(CallAgent.Log_Key, "doBtnDownAction BtnId_Talk_Down curGroupInfo is " + curGroupInfo);
		int callType = callAttr.getCallType();
		String groupNum = callAttr.getGroupInfo().getMcId();//.getGroupNum();
		String curNum = mcIdInfo.getMcId();
//		if(isVideo)
//		{
//			callee = callAttr.getCalled().getMcvideoId();
//			curNum = mcIdInfo.getMcvideoId();
//			mcType = UserInfo.McType_Video;
//		}
		
//		int result = operator.makeCall(SipCallSession.Call_Group,1,curNum, 
//				agent.getOperator( ).getConfig( ).isVideoEnable( ) );
		int result = operator.makeCall(callType,groupNum,curNum);
		if(result != CauseCont.OperateCheck_Suc) 
		{
			String errStr = CauseCont.getOperateCheckErrStr(result,ctx);
			CommDlg.showToast(ctx,errStr);
			return result;
		}
		return CauseCont.OperateCheck_Suc;
	}
	
	public int doAcceptAction()
	{
		Log.d(GroupCallAgent.Log_Key,"doAcceptAction");
		Context ctx = this.getCtx();
		CallOperator operator = this.getOperator();
		if(null == operator
				|| null == ctx)
		{
			String errStr =  Resource.getString("operator_null");//ctx.getString(R.string.operator_null);
			CommDlg.showToast(ctx,errStr);
			return CauseCont.OperateCheck_Sys_UserKeyNull;
		}

//		int mcType = callAttr.getMcType();
//		int callType = callAttr.getCallType();
		String called =  callAttr.getGroupInfo().getMcId();//.getGroupNum();
		String callee = mcIdInfo.getMcId();
//		if(mcType == CallAttr.McType_VIDEO)
//		{
//			called = callAttr.getCalled().getMcvideoId();
//			callee = mcIdInfo.getMcvideoId();
//		}
		
		int result = operator.answerCall(curCallIdStr, CallAttr.CallType_Group,called,callee,false);//.hangupCall(curCallId,486);
		if(result != CauseCont.OperateCheck_Suc) 
		{
			String errStr = CauseCont.getOperateCheckErrStr(result,ctx);
			CommDlg.showToast(ctx,errStr);
			return result;
		}
		return CauseCont.OperateCheck_Suc;
	}
	
	protected int doHangupAction()
	{
		Log.d(GroupCallAgent.Log_Key,"doHangupAction");
		Context ctx = this.getCtx();
		CallOperator operator = this.getOperator();
		if(null == operator
				|| null == ctx)
		{
			String errStr =  Resource.getString("operator_null");//ctx.getString(R.string.operator_null);
			CommDlg.showToast(ctx,errStr);
			return CauseCont.OperateCheck_Sys_UserKeyNull;
		}

		int result = operator.hangupCall(curCallIdStr,603);
		if(result != CauseCont.OperateCheck_Suc) 
		{
			String errStr = CauseCont.getOperateCheckErrStr(result,ctx);
			CommDlg.showToast(ctx,errStr);
			return result;
		}
		return CauseCont.OperateCheck_Suc;
	}
//	protected int floorRelease()
//	{
//		Log.d(GroupCallAgent.Log_Key, "floorRelease");
//		Context ctx = this.getCtx();
//		if(null == operator
//				|| null == ctx)
//		{
//			String errStr =  Resource.getString("operator_null");//ctx.getString(R.string.operator_null);
//			CommDlg.showToast(ctx,errStr);
//			return CauseCont.OperateCheck_Sys_UserKeyNull;
//		}
//		String gNum = addOp.getCurGroupInfo().getMcId();//callAttr.getGroupInfo().getMcId();
//		String uName = mcIdInfo.getUserId();
//		int result = operator.releaseSpeaking(curCallId,gNum,uName);
//		if(result != CauseCont.OperateCheck_Suc)
//		{
//			String errStr = CauseCont.getOperateCheckErrStr(result,ctx);
//			CommDlg.showToast(ctx,errStr);
//			return result;
//		}
//		return CauseCont.OperateCheck_Suc;
//	}
	
	public void startTimer() {
		Log.d(SingleCallAgent.Log_Key, "startTimer");
		
		stopTimer();
		this.keepLiveTimer = new AlarmTimer(ctx,TimerOutKey_Negotiate,40,this);
		keepLiveTimer.startRefreshTimer();
	}
	
	public void stopTimer() {
		Log.d(SingleCallAgent.Log_Key, "stopTimer");
		if(keepLiveTimer != null)
		{
			this.keepLiveTimer.stopRefreshTimer();
			this.keepLiveTimer = null;
		}
		isStartTimer = false;
	}
	
	@Override
	public void timeIntervalTimeout(String alarmAction) {
		// TODO Auto-generated method stub
		Log.d(SingleCallAgent.Log_Key, "timeIntervalTimeout alarmAction = " + alarmAction);
		if(TimerOutKey_Negotiate.equals(alarmAction))
		{
			String uNum = mcIdInfo.getUserId();
			String gNum = addOp.getCurGroupInfo().getMcId();
			this.operator.negotiateRtpRtcpChannel(curCallIdStr,gNum,uNum);
		}
		
	}
	
	public int negotiateRtpRtcpChannel()
	{
		Log.d(GroupCallAgent.Log_Key, "negotiateRtpChannel");
		Context ctx = this.getCtx();
		if(null == operator
				|| null == ctx)
		{
			String errStr =  Resource.getString("operator_null");//ctx.getString(R.string.operator_null);
			CommDlg.showToast(ctx,errStr);
			return CauseCont.OperateCheck_Sys_UserKeyNull;
		}
		String uNum = mcIdInfo.getUserId();
		String gNum = addOp.getCurGroupInfo().getMcId();
		int result = operator.negotiateRtpRtcpChannel(curCallIdStr,gNum,uNum);
		if(result != CauseCont.OperateCheck_Suc) 
		{
			String errStr = CauseCont.getOperateCheckErrStr(result,ctx);
			CommDlg.showToast(ctx,errStr);
			return result;
		}
		return CauseCont.OperateCheck_Suc;
	}

	public int negotiateRtcpChannel()
	{
		Log.d(GroupCallAgent.Log_Key, "negotiateRtpChannel");
		Context ctx = this.getCtx();
		if(null == operator
				|| null == ctx)
		{
			String errStr =  Resource.getString("operator_null");//ctx.getString(R.string.operator_null);
			CommDlg.showToast(ctx,errStr);
			return CauseCont.OperateCheck_Sys_UserKeyNull;
		}
		String uNum = mcIdInfo.getUserId();
		String gNum = addOp.getCurGroupInfo().getMcId();
		int result = operator.negotiateRtcpChannel(curCallIdStr,gNum,uNum);
		if(result != CauseCont.OperateCheck_Suc)
		{
			String errStr = CauseCont.getOperateCheckErrStr(result,ctx);
			CommDlg.showToast(ctx,errStr);
			return result;
		}
		return CauseCont.OperateCheck_Suc;
	}
//	protected int doExitAction()
//	{
//		Context ctx = this.getCtx();
//		CallOperator operator = this.getOperator();
//		if(null == operator
//				|| null == ctx)
//		{
//			String errStr =  Resource.getString("operator_null");//ctx.getString(R.string.operator_null);
//			CommDlg.showToast(ctx,errStr);
//			return CauseCont.OperateCheck_Sys_UserKeyNull;
//		}
//		
//		int result = operator.hangupCall(SipCallSession.Call_Group);
//		if(result != CauseCont.OperateCheck_Suc) 
//		{
//			String errStr = CauseCont.getOperateCheckErrStr(result,ctx);
//			CommDlg.showToast(ctx,errStr);
//			return result;
//		}
//		return CauseCont.OperateCheck_Suc;
//	}

	public void destoryCall()
	{
		Log.d(GroupCallAgent.Log_Key, "destoryCall");
		Context ctx = this.getCtx();
		CallOperator operator = this.getOperator();
		if(null == operator
				|| null == ctx)
		{
			String errStr =  Resource.getString("operator_null");//ctx.getString(R.string.operator_null);
			CommDlg.showToast(ctx,errStr);
			return;
		}
		operator.destoryCall(curCallIdStr);
	}

	public Context getCtx() {
		return ctx;
	}

	public CallOperator getOperator() {
		return operator;
	}

	public void clearGroupCall() 
	{
		Log.d(GroupCallAgent.Log_Key,"clearGroupCall");
		int result = operator.hangupCall(curCallIdStr,0);
		if(result != CauseCont.OperateCheck_Suc) 
		{
			String errStr = CauseCont.getOperateCheckErrStr(result,ctx);
			CommDlg.showToast(ctx,errStr);
			return;
		}
	}

	public CallListener getListener() {
		return listener;
	}

	public String getCurCallIdStr() {
		return curCallIdStr;
	}
	public String getCallkey() {
		return callkey;
	}

	public String getSysInfoStr()
	{
		StringBuffer strBuf = new StringBuffer("GroupCallAgent:");
		strBuf.append(callkey).append("-").append(callAttr);
		return strBuf.toString();
	}
	
	public void updateCallDuration(int sec)
	{
//		this.timeDesc = Common.getTime(sec);
//		if(this.listener != null)
//		{
//			listener.updateCallDuration(callkey, ""+ timeDesc);
//		}
	}
	
	public CallAttr getCallAttr() {
		return callAttr;
	}
	public String getTimeDesc() {
		Log.d(GroupCallAgent.Log_Key, "getTimeDesc timeDesc = " + timeDesc);
		return timeDesc;
	}
	
	private final static int MsgId_Release = 1;
	private  Handler mHandler = new Handler(){ 
		@Override
		public void handleMessage(Message msg)
		{
			if(msg.what == MsgId_Release)
			{
				Log.d(GroupCallAgent.Log_Key, "mHandler MsgId_Release");
//				
				if(floorAgent != null)
				{
					int result = floorAgent.doUserAction(CallConst.BtnAction_Release);
					if(CauseCont.OperateErr_Invalid == result)
					{
						Log.d(GroupCallAgent.Log_Key, "mHandler MsgId_Release OperateErr_Invalid");
						Message newMsg = mHandler.obtainMessage(MsgId_Release);
						mHandler.sendMessageDelayed(newMsg, 500);
					}
					isRecvRelease = false;
				}
				else
				{
					Log.d(GroupCallAgent.Log_Key, "mHandler MsgId_Release floorAgent == null");
					Message newMsg = mHandler.obtainMessage(MsgId_Release);
					mHandler.sendMessageDelayed(newMsg, 1000);
				}
				
				
			}
		}
	};

	@Override
	public void muteCall(boolean isOn) {
		// TODO Auto-generated method stub
		operator.muteCall(curCallIdStr, isOn);//.holdGroupCall(curCallId);
	}
	
}
